package com.cc.pms.controller;


import com.cc.pms.service.ITeamService;
import com.cc.common.core.domain.R;
import com.cc.common.core.page.PageQuery;
import com.cc.common.core.page.PageVo;
import com.cc.pms.domain.vo.TeamVo;
import com.cc.pms.domain.vo.UserVo;
import com.cc.pms.service.IUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/matching")
public class MatchingController {

    @Resource
    private ITeamService iTeamService;

    @Resource
    private IUserService iUserService;


    @GetMapping("/team/by-invite-code")
    public R<TeamVo> queryTeamByInviteCode(@RequestParam(value = "inviteCode" , required = false) String inviteCode){
        return R.ok(iTeamService.queryTeamVoByInviteCode(inviteCode));
    }

    @GetMapping("/team/search-by-name")
    public R<PageVo<TeamVo>> queryTeamByName(PageQuery query ,@RequestParam(value = "name" , required = false) String name){
        return R.ok(iTeamService.queryTeamVoByName(query , name));
    }

    @GetMapping("/team/by-tags")
    public R<PageVo<TeamVo>> queryTeamByTags(PageQuery query , Long[] tagIds){
        return R.ok(iTeamService.queryTeamVoByTagIds(query , tagIds == null ? null : Arrays.stream(tagIds).collect(Collectors.toList())));
    }


    @GetMapping("/users/by-account")
    public R<UserVo> queryUserByInviteCode(@RequestParam(value = "userId", required = false) Long userId){
        return R.ok(iUserService.queryUserVoListByUserId(userId));
    }

    @GetMapping("/users/by-name")
    public R<PageVo<UserVo>> queryUserByName(PageQuery query ,@RequestParam(value = "userName" , required = false) String userName){
        return R.ok(iUserService.queryUserVoListByUserName(query ,userName));
    }

    @GetMapping("/users/by-tags")
    public R<PageVo<UserVo>> queryUserByTags(PageQuery query , @RequestParam(value = "tagIds" , required = false) Long[] tagIds){
        return R.ok(iUserService.queryUserVoListByTagIds(query , tagIds == null ? null : Arrays.stream(tagIds).collect(Collectors.toList())));
    }






}
